package com.greenova.theprojector.biz.entities.repository;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import com.greenova.theprojector.biz.entities.Employee;

@Repository
public class EmployeeRepository implements SimpleRepository<Employee>{
	private static final Logger logger = LoggerFactory.getLogger(EmployeeRepository.class);
	private Map<Integer,Employee> employeeMap;
	private Map<Integer,Employee> unassignedMap;
	
	public EmployeeRepository(){
		super();
				
		employeeMap = new LinkedHashMap<Integer,Employee>();
		unassignedMap = new LinkedHashMap<Integer,Employee>();
		
		Employee dummy1 = new Employee();
		dummy1.setEmployeeId(new Integer(1));
		dummy1.setFirstName("Harley");
		dummy1.setLastName("Pascua");
		
		Employee dummy2 = new Employee();
		dummy2.setEmployeeId(new Integer(2));
		dummy2.setFirstName("Patrick");
		dummy2.setLastName("Bautista");
		
		Employee dummy3 = new Employee();
		dummy3.setEmployeeId(new Integer(3));
		dummy3.setFirstName("Third");
		dummy3.setLastName("Employee");
		
		Employee dummy4 = new Employee();
		dummy4.setEmployeeId(new Integer(4));
		dummy4.setFirstName("Fourth");
		dummy4.setLastName("Employee");
		
		Employee dummy5 = new Employee();
		dummy5.setEmployeeId(new Integer(5));
		dummy5.setFirstName("Fifth");
		dummy5.setLastName("Employee");
		
		employeeMap.put(dummy1.getEmployeeId(), dummy1);
		employeeMap.put(dummy2.getEmployeeId(), dummy2);
		unassignedMap.put(dummy3.getEmployeeId(), dummy3);
		unassignedMap.put(dummy4.getEmployeeId(), dummy4);
		unassignedMap.put(dummy5.getEmployeeId(), dummy5);
	}
	
	@Override
	public List<Employee> findAll() {
		return new ArrayList<Employee>(employeeMap.values());
	}
	
	public List<Employee> findAllUnassigned() {
		return new ArrayList<Employee>(unassignedMap.values());
	}

	public Employee findAssignedById(final Integer id) {
        return this.employeeMap.get(id);
    }
	
	public Employee findUnassignedById(final Integer id) {
        return this.unassignedMap.get(id);
    }
	
	public void addAssigned(Employee employee){
		employeeMap.put(employee.getEmployeeId(), employee);
		logger.debug("Assigned Employees:" + employeeMap);
	}
	
	public void addUnassigned(Employee employee){
		unassignedMap.put(employee.getEmployeeId(), employee);
		logger.debug("Unassigned Employees:" + unassignedMap);
	}
	
	public void removeAssigned(Employee employee){
		employeeMap.remove(employee.getEmployeeId());
		logger.debug("Assigned Employees:" + employeeMap);
	}
	
	public void removeUnassigned(Employee employee){
		unassignedMap.remove(employee.getEmployeeId());
		logger.debug("Unassigned Employees:" + unassignedMap);
	}
}
